package com.gongj.hystrix.Command;

import com.gongj.commons.pojo.User;
import com.gongj.hystrix.service.HystrixService;
import com.gongj.hystrix.service.UserService;
import com.netflix.hystrix.HystrixCommand;
import com.netflix.hystrix.HystrixCommandGroupKey;
import com.netflix.hystrix.HystrixCommandKey;

import java.util.List;

/**
 * @program: cloudlx
 * @description: 请求分发 相当于MyHystrixCommand
 * @author: gongj
 * @Description: TODO
 * @create: 2020-06-19 14:27
 **/
public class UserBatchCommand extends HystrixCommand<List<User>> {
    private List<String> ids;
    private UserService userService;

    public UserBatchCommand(List<String> ids, UserService userService) {
        super(HystrixCommand.Setter.withGroupKey(
                HystrixCommandGroupKey.Factory.asKey("gongjbatchCmd"))
                .andCommandKey(HystrixCommandKey.Factory.asKey("gongjbatchKey")));
        this.ids = ids;
        this.userService = userService;
    }

    @Override
    protected List<User> run() throws Exception {
        return userService.getUsersByIds(ids);
    }
}